/*
 * Copyright (C) 2010-2014 Enrique Lara (enrique.posix2.lara@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package app.transittool;

import android.app.Activity;

import android.os.Bundle;

import android.text.Html;

import android.text.method.LinkMovementMethod;

import android.view.MotionEvent;

import android.widget.TextView;

import app.transittool.model.App;

import app.transittool.util.Constants;

public final class About extends Activity {
    private FlingLeftRightGestureListener flingListener;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
        setTitle(getText(R.string.about));

        final TextView txt = (TextView) findViewById(R.id.text);

        final StringBuilder buff = new StringBuilder();

        if (App.isDebug()) {
            for (final String msg : App.getDebugMessages()) {
                buff.append("<hr />");
                buff.append("<pre>");
                buff.append(msg);
                buff.append("</pre>");
            }
        } else {
            buff.append("<h1>" + getText(R.string.app_name) + " " + getText(R.string.app_version) + "</h1>");
            buff.append("<h2>Note</h2>" + "<div>" + "This application is intended to help minimize your wait time by giving " + "you a head's up for a train/bus that meets your criteria.<br /><br />" + "Two warnings:<br />" + "1) There may never be that perfect ride.<br />" + "2) This application definitely has bugs.<br /><br />");
            buff.append("As Daedalus warned Icarus, \"Don't go to the stop too early or the sun may melt your wings. Too close to the estimated arrival time and you may drown in an ocean of tears.\"<br /><br />");
            buff.append("Thanks,<br />" + "Enrique" + "</div>");
            buff.append("<h2>Copyright</h2>" + "<div>" + "Copyright 2010-2014 Enrique Lara <enrique.posix2.lara@google.com><br />" + "<br />");
            buff.append("Licensed under the Apache License, Version 2.0 (the \"License\"); " + " you may not use this file except in compliance with the License.<br />" + "You may obtain a copy of the License at<br />" + "<br />" + "<a href=\"http://www.apache.org/licenses/LICENSE-2.0\">http://www.apache.org/licenses/LICENSE-2.0</a><br />" + "<br />" + "Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  " + "See the License for the specific language governing permissions and limitations under the License.<br />" + "</div>");
            buff.append("<h1>License/Credits</h1>");
            buff.append("<h2>WMATA Data</h2>" + "<div>" + "All transit data is provided by the Washington Metropolitan Area Transit Authority.<br />" + "<a href=\"http://www.wmata.com\">http://www.wmata.com</a><br />" + "</div>");
            buff.append("<h2>Code from ApiDemos</h2>" + "<div>" + "This software borrows constructs from the ApiDemos project.  " + "That project was distributed under the Apache License, Version 2.0, and was written by The Android Open Source Project<br />" + "</div>");
            buff.append("<h2>Logo</h2>" + "<div>" + "The logo is a modification based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.  This application also comes bundles with icons from the Google android project.<br />" + "</div>");
        }

        txt.setText(Html.fromHtml(buff.toString()));

        txt.setMovementMethod(LinkMovementMethod.getInstance());

        flingListener = new FlingLeftRightGestureListener(this, Constants.ACTION_NEARBY_STOPS, Constants.ACTION_SETTINGS);
    }

    @Override
    public boolean dispatchTouchEvent(final MotionEvent ev) {
        flingListener.dispatchTouchEvent(ev);

        return super.dispatchTouchEvent(ev);
    }
}
